import {Injectable} from '@angular/core';
import {InMemoryDbService} from 'angular-in-memory-web-api';

@Injectable({
  providedIn: 'root',
})
export class InMemoryDataService implements InMemoryDbService {
  createDb(): any {
    const heroes = [
      {id: 11, name: 'Dr Nice'},
      {id: 12, name: 'Narco'},
      {id: 13, name: 'Bombasto'},
      {id: 14, name: 'Celeritas'},
      {id: 15, name: 'Magneta'},
      {id: 16, name: 'RubberMan'},
      {id: 17, name: 'Dynama'},
      {id: 18, name: 'Dr IQ'},
      {id: 19, name: 'Magma'},
      {id: 20, name: 'Tornado'}
    ];
    const basicInfo = {
      ip: '192.168.0.211',
      baseBoard: {
        Manufacturer: 'Intel Corporation',
        Product: '440BX Desktop Reference Platform',
        SerialNumber: 'None',
        Version: 'None'
      },
      basicInfo: {
        hostName: 'DESKTOP-GU900F7',
        model: 'VMware7,1',
        os: 'Microsoft Windows 10 专业版',
        osArch: '64 位'
      },
      cpu: [
        {
          l2CacheSize: '0',
          l3CacheSize: '0',
          manufacturer: 'GenuineIntel',
          name: 'Intel(R) Xeon(R) CPU E3-1220 v6 @ 3.00GHz',
          numberOfCores: '4',
          speed: '3000',
          threadCount: '0'
        }
      ],
      disk: [
        {
          name: 'VMware Virtual NVMe Disk',
          serialNumber: 'VMWare NVME_0000',
          size: '64420392960'
        }
      ],
      gpu: [
        {
          caption: 'VMware SVGA 3D',
          driverDate: '20191018000000.000000-000',
          driverVersion: '8.16.7.5',
          rawSize: 0
        }
      ],
      memory: [
        {
          capacity: '8589934592',
          manufacturer: 'VMware Virtual RAM',
          partNumber: 'VMW-8192MB',
          serialNumber: '00000001',
          speed: '0'
        }
      ]
    };
    return {heroes, basicInfo};
  }

  // Overrides the genId method to ensure that a hero always has an id.
  // If the heroes array is empty,
  // the method below returns the initial number (11).
  // if the heroes array is not empty, the method below returns the highest
  // hero id + 1.
  genId(heroes: any[]): number {
    return heroes.length > 0 ? Math.max(...heroes.map(hero => hero.id)) + 1 : 11;
  }
}
